package com.my.content.ui_homework;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RadioButton;

import com.my.content.ui_homework.fragment.FindPage.FindSaleFragment;
import com.my.content.ui_homework.fragment.FirstPage.FirstPagerFragment;
import com.my.content.ui_homework.fragment.HomePage.HomePageFragment;
import com.my.content.ui_homework.fragment.MinePageFragment;
import com.my.content.ui_homework.fragment.StarSale.StarSaleFragment;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.rl_layout,new FirstPagerFragment());
        RadioButton rb = (RadioButton) findViewById(R.id.btn_one);
        rb.setChecked(true);
        transaction.commit();
        findViewById(R.id.btn_one).setOnClickListener(this);
        findViewById(R.id.btn_two).setOnClickListener(this);
        findViewById(R.id.btn_three).setOnClickListener(this);
        findViewById(R.id.btn_four).setOnClickListener(this);
        findViewById(R.id.btn_five).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        switch (view.getId()){
            case R.id.btn_one:
                transaction.replace(R.id.rl_layout,new FirstPagerFragment());
                break;
            case R.id.btn_two:
                transaction.replace(R.id.rl_layout,new StarSaleFragment());
                break;
            case R.id.btn_three:
                transaction.replace(R.id.rl_layout,new HomePageFragment());
                break;
            case R.id.btn_four:
                transaction.replace(R.id.rl_layout,new FindSaleFragment());
                break;
            case R.id.btn_five:
                transaction.replace(R.id.rl_layout,new MinePageFragment());
                break;
        }
        transaction.commit();
    }
}
